<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        #div1{
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute;
        }
    </style>
    <script>
        window.onload = function () {
            var oDiv = document.getElementById("div1");
            oDiv.onmousedown = function (e) {

                var timer = new Date().getTime()

                

                var event = e || event

                disX = event.clientX - oDiv.offsetLeft
                disY = event.clientY - oDiv.offsetTop

                // console.log(document)
                document.onmousemove = function (e) {

                    var event = e || event

                    oDiv.style.left = event.clientX - disX + "px"
                    oDiv.style.top = event.clientY - disY + "px"

                    // console.log(oDiv.style.left)
                    // console.log(oDiv.style.top)
                }

                document.onmouseup = function () {
                    document.onmousemove = null
                    document.onmouseup = null

                    var timer2 = new Date().getTime()


                    console.log(timer2 - timer)
                }
            }
        }
        
    </script>
</head>
<body>
    <div id="div1"></div>
</body>
</html>